
#include  <msp430x54xA.h>
#include  "Drivers.h"
#include  "..\ESS_CommonDefine.h"

/*
    MosFET Control configuration 
    P9.7 CHG control
    P9.6 DSG control
*/
static unsigned char CHGflag=0;
static unsigned char DSGflag=0;

void InitMosControl(){

  // Set up pins used by IO unit
  MOSFET_PORT_SEL &= ~(MOSFET_CHG + MOSFET_DSG);
  MOSFET_PORT_DIR |= MOSFET_CHG + MOSFET_DSG;
  MOSFET_PORT_OUT &= ~(MOSFET_CHG + MOSFET_DSG);
  CHGflag=0;
  DSGflag=0;
  
  //DSG MOS inverse
  MOSFET_PORT_OUT |= MOSFET_DSG;
  //CHG MOS inverse
  MOSFET_PORT_OUT |= MOSFET_CHG;
}

void setMosCHG(char enable){
  if(enable){
    MOSFET_PORT_OUT &= ~(MOSFET_CHG);
    CHGflag = enable;
  }else{
    MOSFET_PORT_OUT |= (MOSFET_CHG);
    CHGflag = enable;
  }
}
void setMosDSG(char enable){
  if(enable){
    MOSFET_PORT_OUT &= ~(MOSFET_DSG);
    DSGflag = enable;
  }else{
    MOSFET_PORT_OUT |= (MOSFET_DSG);
    DSGflag = enable;
  }
}
/*
void setMosCHG(char enable){
  if(enable){
    MOSFET_PORT_OUT |= (MOSFET_CHG);
    CHGflag = enable;
  }else{
    MOSFET_PORT_OUT &= ~(MOSFET_CHG);
    CHGflag = enable;
  }
}
*/
/*
void setMosDSG(char enable){
  if(enable){
    MOSFET_PORT_OUT |= (MOSFET_DSG);
    DSGflag = enable;
  }else{
    MOSFET_PORT_OUT &= ~(MOSFET_DSG);
    DSGflag = enable;
  }
}
*/


char getMosCHG(){
  return CHGflag;
}
char getMosDSG(){
  return DSGflag;
}
